# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=dmake
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.12.2.2
pkgrel=1
pkgdesc="Dmake is a make utility similar to GNU make or the Workshop dmake (mingw-w64)"
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
license=('GPL')
url="https://github.com/mohawk2/${_realname}"
pkgver2="$(echo ${_realname} | tr '[:lower:]' '[:upper:]')_$(echo ${pkgver} | sed 's/\./_/g')"
source=("${url}/archive/${pkgver2}.tar.gz"
        '001-detect-mingw.patch'
        '002-disable-shell-environment-variable.patch'
        '003-fix-config-location.patch'
        '004-disable-mkstemp-detection.patch')
sha256sums=('3d412e0afea9d27416c359acb05611ab17f608cafe14ebfdc1410bd4e8e9575c'
            'e94563064537be35c7fd2d91b814f389223482fb520799a71ac18226f70114e7'
            'b6aacca13803eb0d5276388039889396ea0a9a66b12c5b83aad689e56f774174'
            '21a6b60086e068061d9af1a499bd9134b6eacabbb2f3ad9b071b4657c983428b'
            'd77e6b41b15090c63694fbf2c4740fb6ce6009394b701984aa8e2beff376906d')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver2}
  patch -p1 -i ${srcdir}/001-detect-mingw.patch
  patch -p1 -i ${srcdir}/002-disable-shell-environment-variable.patch
  patch -p1 -i ${srcdir}/003-fix-config-location.patch
  patch -p1 -i ${srcdir}/004-disable-mkstemp-detection.patch
}

build() {
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../${_realname}-${pkgver2}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --datarootdir=${MINGW_PREFIX}/etc/dmake \
    --build=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
